
package org.apache.solr.core;

import org.apache.solr.common.params.EventParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.search.SolrIndexSearcher;

public class AbstractSolrEventListener implements SolrEventListener {

    protected final SolrCore core;

    public AbstractSolrEventListener(SolrCore core) {
        this.core = core;
    }
    protected NamedList args;

    @Override
    public void init(NamedList args) {
        this.args = args;
    }

    @Override
    public void postCommit() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void postSoftCommit() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher) {
        throw new UnsupportedOperationException();
    }

    @Override
    public String toString() {
        return getClass().getName() + args;
    }

    /**
     * Add the {@link org.apache.solr.common.params.EventParams#EVENT} with
     * either the {@link org.apache.solr.common.params.EventParams#NEW_SEARCHER}
     * or {@link org.apache.solr.common.params.EventParams#FIRST_SEARCHER}
     * values depending on the value of currentSearcher.
     * <p/>
     * Makes a copy of NamedList and then adds the parameters.
     *
     *
     * @param currentSearcher If null, add FIRST_SEARCHER, otherwise
     * NEW_SEARCHER
     * @param nlst The named list to add the EVENT value to
     */
    protected NamedList addEventParms(SolrIndexSearcher currentSearcher, NamedList nlst) {

        NamedList result = new NamedList();
        result.addAll(nlst);
        if (currentSearcher != null) {
            result.add(EventParams.EVENT, EventParams.NEW_SEARCHER);
        }
        else {
            result.add(EventParams.EVENT, EventParams.FIRST_SEARCHER);
        }
        return result;
    }
}
